<template>
	<view class="content">
		<view class="card">
			<!-- <view class="card_title">营业执照上传</view> -->
			<view class="card_content" @click="chooseImg">
				<image :src="tempFilePaths" mode=""></image>
			</view>
		</view>
		<my-issue key="1" @scoreChange='scoreChange' :infoReceive='infoReceive' @submit="submit"/>
	</view>
</template>

<script>
  import myIssue from '@/components/myIssue.vue'
	export default {
		components:{myIssue},
		data() {
			return {
				title: 'Hello',
				infoReceive:{
					score:0,
					textareaValue:""
				},
				order_num:'',
				tempFilePaths:'/static/btn_up.png',
				pic_list:''
			}
		},
		onLoad(option) {
			this.order_num = option.order_num
		},
		methods: {
			scoreChange(score){
				this.infoReceive.score = score;
			},
			submit(data){
				if(!data.score){
					uni.showModal({
						title: '提示',
						content: '请选中星级',
						showCancel: false,
					});
					return false
				}
				if(!data.textareaValue){
					uni.showModal({
						title: '提示',
						content: '评价一下宝贝吧',
						showCancel: false,
					});
					return false
				}
				
				this.star = data.score;
				this.content = data.textareaValue;
				this.mallCommentLogsSave();
			},
			//上传评价
			mallCommentLogsSave(){
				var _this = this;
				uni.request({
					url:this.$API.mallCommentLogsSave,
					method:"POST",
					data:{
						"mall_comment_logs.u_id":uni.getStorageSync("userid"),
						"mall_comment_logs.order_id":this.order_num,
						"mall_comment_logs.pic_list":this.pic_list,
						"mall_comment_logs.star":this.star,
						"mall_comment_logs.content":this.content,
					},
					header:this.$API.get_head(),
					success: (res) => {
						if(res.data.success){
							uni.navigateBack({
								delta: 1
							});
						}
						uni.showToast({
							title: res.data.message
						});
						// console.log(res.data.success)
					},
					fail: () => {
						uni.showToast({
							title:"加载失败",
							icon:'none'
						})
					}
				})
			},
			chooseImg(){
				var _this = this;
				uni.chooseImage({
					sourceType: ["camera", "album"],
					sizeType: "compressed",
					count:9,
					success: (res) => {
						_this.tempFilePaths = res.tempFilePaths;
						// console.log(res.tempFilePaths[0])
						uni.uploadFile({
							url: this.$API.upload,
							headers:{
								"content-type":"application/x-www-form-urlencoded",
							},
							name: 'file',
							filePath: res.tempFilePaths[0],
							success: function(res) {
								var data = JSON.parse(res.data)
								// console.log(data)
								if(data.msg=="success"){
									_this.pic_list = data.fileName;
									// console.log(data)
								}
							},
							fail: function(res) {
								uni.showToast({
									title:"上传失败",
									icon:'none'
								})
								// console.log('上传失败', res);
							}
						});
					}
				});
			},
		}
	}
</script>

<style>
	.content{
		height: 100%;
	}
	
	.card{
		margin-top:20upx;
		background:#FFFFFF;
		color:#333333;
	}
	.card .card_title{
		border-bottom:1upx solid #e9e9e9;
		font-size:32upx;
		padding:40upx 25upx;
	}
	.card .card_content{
		padding: 23upx 25upx;
	}
	.card .card_content>image{
		width:327upx;
		height:245upx;
	}
</style>
